﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace Dzzzr.DataLayer
{
  class Helper
  {
    public static SqlConnection Connection
    {
      get
      {
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString);
        cnn.Open();
        return cnn;
      }
    }

		public static SqlDatabase DB
		{
			get
			{
				SqlDatabase db = new SqlDatabase(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString);
				return db;
			}
		}

    public static SqlParameter CreateInputParam(string paramName,
                                           SqlDbType dbType,
                                           object objValue)
    {

      SqlParameter param = new SqlParameter(paramName, dbType);

      if (objValue == null)
      {
        param.IsNullable = true;
        param.Value = DBNull.Value;
      }
      else
      {
        param.Value = objValue;
      }

      return param;
    }


  }
}
